var app = new Framework7({
  // App root element
  root: '#app',
  panel: {
    swipe: 'left',
  },
  touch: {
    activeState: false
  },
  dialog: {
	title: '提示',
    buttonOk: "确定",
    buttonCancel: "取消"
  },
  photoBrowser: {
    backLinkText: '关闭',
  },
  routes: routes,
});

var mainView = app.views.create('.view-main');

var $$ = Dom7;

// Tab选择
$$(".toolbar a.link").on("click", function(){
    $$(this).addClass("active").siblings(".toolbar a.link").removeClass("active");
});

// $$(".tabbar .tab-link").on("click", function(){
//     $$(this).addClass("tab-link-active").siblings(".tabbar .tab-link").removeClass("tab-link-active");
//     var curindex = $$(this).index();
//     var curselector = "#tab-" + curindex;
//     $$(curselector).addClass("tab-active").siblings().removeClass("tab-active");
// });
$$('div.toolbar-inner a.link').each(function(){
	var surl = window.location.href;
	if (surl.indexOf($$(this).attr('href'))>=0){
		$$(this).addClass('active');
	}else{
		$$(this).removeClass('active');
	}
});


// app.views.main.router.navigate({ name: 'login' });
// <a href="/login-screen/" class="">login Page</a>
// <a href="/album/" class="">album Page</a>			
// for(var p in page){
//   console.log(p + " " + page[p]);
// }
	

/* 初始化函数 */
// app.on('pageInit', function (page) {
// 	if (page.route.name == "login"){ login_init(); }
// });
$$('#btn_show_toolbar_classes').on('click', function(){
	//app.popup.open($$('div.popup-toolbar-classes'));
});
var bf_popup_toolbar_classes = false;
$$('.popup-choose').on('popup:open', function (e, popup) {
	if (bf_popup_toolbar_classes) return;
	sendPost('/front/teacher/user/getClasses', null, function(res){
		//console.log(res);
		if (res.code == 200){
			
			$$('#btn_show_toolbar_classes').attr('class-id', res.rd_teacher.class_id).text(res.rd_teacher.class_name);
			
			var shtml = '';
			for(var i=0, l=res.list_classes.length; i<l; i++){
				var p = res.list_classes[i];
				shtml += '<li><a href="#" class-id="'+p.class_id+'">'+p.class_name+'</a></li>';
			}
			$$('#ul-toolbar-classes').html(shtml);
			bf_popup_toolbar_classes = true;
			
			$$('#ul-toolbar-classes a').on("click", function(){
				var cname = $$(this).text();
				var cid = $$(this).attr('class-id');
				//console.log(cname);
				$$('#btn_show_toolbar_classes').attr('class-id', cid).text(cname);
				app.popup.close($$('div.popup-toolbar-classes'));
			});
		}
	});
});








